<template>
  <div class="wrap w-order detail w-index">
    <header>
        <img onclick="javascript :history.back(-1);" src="@/assets/img/l_b.png" alt="" />
        全部订单
    </header>
    <div class="content">
        <div class="swiper-container gallery-thumbs">
            <div class="swiper-wrapper">
                <div class="swiper-slide" @click="tabList" data-index="0">招标中</div>
                <div class="swiper-slide" @click="tabList" data-index="1">已中标</div>
                <div class="swiper-slide" @click="tabList" data-index="2">未中标</div>
                <div class="swiper-slide" @click="tabList" data-index="3">报价人数不足</div>
                <div class="swiper-slide" @click="tabList" data-index="4">效益作废</div>
                <div class="swiper-slide" @click="tabList" data-index="5">拒收</div>
                <div class="swiper-slide" @click="tabList" data-index="6">等待确认结果</div>
                <div class="swiper-slide" @click="tabList" data-index="7">成交</div>
            </div>
        </div>
        <!-- Swiper -->
        <div class="swiper-container gallery-top">
        </div>
        <div class="tab">
              <div class="con con1 con2 con3" style="display: block;" v-for="(val,index) in bidList" :key="index">
                <div class="item" :data-bidid="val.bid_id" @click="toDetail">
                  <div class="name clearfix">
                    <div class="flag">{{val.bid_type}}</div>
                    <h3>{{val.bid_name}}</h3>

                    <button :data-bidId="val.bid_id" :data-id="index" type="primary" size="mini" plain="true" @click.stop="istrue"  v-if="val.is_true==0">确认</button>
                    <button disabled="true" type="primary" size="mini" plain="true" v-if="val.is_true==1">已确认</button>

                  </div>
                  <div class="text">
                    <!--上下三角-->
                    <div :class="!val.show_remark ? 'font' : 'font show-text'">
                    {{val.bid_remark}}
                    </div>
                    <div :class="!val.show_remark ? 'icon' : 'icon show-text'" @click.stop="showTxt(index)">
                        <img :src="!val.show_remark ? up_img : down_img" alt="" />
                    </div>
                  </div>
                  <div class="infos clearfix">
                    <div class="right">
                        <div class="list">
                            发布者：{{val.bid_user_company}}
                        </div>
                        <div class="list">
                            竞标人数：{{val.bid_enlist_num}}
                        </div>
                        <div class="list">
                            位置：{{val.city_id}}
                        </div>
                        <div class="list">
                            日期：{{val.time}}
                        </div>
                    </div>
                  </div>
                </div>
              </div>
          </div>

    </div>

    <Bartab />

</div>

</template>
<script>
import Bartab from '@/components/Bartab.vue'
import Swiper from 'swiper';
//上三角 ，下三角
import up_img from '@/assets/img/up.png'
import down_img from '@/assets/img/down.png'

export default {
  name: 'home',
  data(){
    return{
      is_show:true,
      navData: [{text: '招标中'},{text: '已中标'},{text: '未中标'},{text: '报价人数不足'},
      {text: '效益作废'},{text: '拒收'},{text: '等待确认结果'},{text: '成交'}],

      bidList:{},
      tab:0,
      currentTab: 0, //导航菜单使用数据
      navScrollLeft: 0, //导航菜单使用数据
      lts2: {},
      isNull: true,


      //上下三角
      down_img:down_img,
      up_img:up_img,
      //swiper 
      swiper1:'',
      swiper2:'',


    }
  },
  async created(){
        let user_token = this.getUserToken()
        let tab = this.$route.query.id?this.$route.query.id:0;

        let re = await this.$axios.post('bid/statusBidList',{
          user_token:user_token,
          tab:tab
        })
        if(re.code == 200){
           this.bidList = re.data
        }
    
  },
  methods:{
    //确认按钮
   async istrue(e){
        let bidid = e.currentTarget.getAttribute('data-bidid')
        let id = e.currentTarget.getAttribute('data-id')
        let arr = this.bidList;

        let res = await this.$axios.post('bid/isTrue',{
          bid_id:bidid
        })
        if(res.code == 200){
            arr[id].is_true = 1
            this.bidList = arr
        }
    },
    //标书详情
    async toDetail(e){
      let that =this;
      let bidid = e.currentTarget.getAttribute('data-bidid')
      //let  tabnum  =  e.currentTarget.dataset.tabnum;
      let user_token = this.getUserToken()
      let res = await this.$axios.post('bid/getGoWhere',{
          bid_id:bidid,
          user_token:user_token
        })
          if(res.code == 200){
              this.$router.push({path:'/bid/'+res.data.toWhere,query: {
              bid_id: bidid,
              redirect:'/my/bidlist'
             }})
          }
          
     },

    //上下三角
    showTxt(index){
        let arr =this.bidList;
        if (arr[index].show_remark == false) {
          arr[index].show_remark = true;
        } else {
          arr[index].show_remark = false;
        }
        this.bidList = arr

    },
    //tab 切换
    async tabList(e){
        let user_token = this.getUserToken()
        let tab = e.target.getAttribute('data-index');

        let re = await this.$axios.post('bid/statusBidList',{
          user_token:user_token,
          tab:tab
        })
        if(re.code == 200){
           this.bidList = re.data
        }
              
        

    },
    reback(){
        if(this.$route.query.redirect){
             this.$router.replace({path:this.$route.query.redirect})
        }else{
             this.$router.replace({path:'/'})
        }
    }

  
  },
  mounted(){
      this.swiper1 = new Swiper('.gallery-thumbs', {          
          spaceBetween: 10,//在slide之间设置距离
          initialSlide :1,
          slidesPerView: 3,//同时显示的slides数量
          centeredSlides: true,

          freeMode: true,//惯性滑动可能不止一格
          watchSlidesVisibility: true,
          watchSlidesProgress: true,
        });
      this.swiper2 = new Swiper('.gallery-top', {
        spaceBetween: 10,
        thumbs: {
          swiper: this.swiper1,
        },
      });
      let tab = this.$route.query.id;
      if(tab > 0){
        this.swiper1.slideTo(tab,0,false);
        this.swiper2.slideTo(tab,0,false);
      }
        


    
  },
  components: {
    'Bartab':Bartab
  }
}
</script>
